package com.ck.ips.controller.sys;

import com.ck.common.model.Department;
import com.ck.common.page.PageInfo;
import com.ck.core.annotation.LoginRequired;
import com.ck.core.annotation.SysLog;
import com.ck.core.constant.ModuleConstant;
import com.ck.ips.controller.BaseController;
import com.ck.ips.model.vo.sys.DepartmentListVO;
import com.ck.ips.service.sys.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@LoginRequired
@RestController
@RequestMapping(value = "/department")
public class  DeparmentController extends BaseController {

	@Autowired
	private DepartmentService departmentService;

	/**
	 * 保存部门
	 */
	@SysLog(module = ModuleConstant.MODULE_DEPARTMENT)
	@PostMapping("/save")
	public Object saveDepartment(String departmentName, Integer status, String departmentDesc, String phoneNumber, String fax, String departmentCode, Long parentId) {
		Department department = new Department();
		department.setDepartmentName(departmentName);
		department.setStatus(status);
		department.setDepartmentDesc(departmentDesc);
		department.setPhoneNumber(phoneNumber);
		department.setFax(fax);
		department.setDepartmentCode(departmentCode);
		department.setParentId(parentId);
		return departmentService.insertDepartment(department);
	}

	/**
	 * 修改部门
	 */
	@SysLog(module = ModuleConstant.MODULE_DEPARTMENT)
	@PostMapping("/update")
	public Object updateDepartment(String departmentName, Long departmentId, Integer status, String departmentDesc, String phoneNumber, String fax, String departmentCode, Long parentId) {
		Department department = new Department();
		department.setDepartmentId(departmentId);
		department.setDepartmentName(departmentName);
		department.setStatus(status);
		department.setDepartmentDesc(departmentDesc);
		department.setPhoneNumber(phoneNumber);
		department.setFax(fax);
		department.setDepartmentCode(departmentCode);
		department.setParentId(parentId);
		return departmentService.updateDepartment(department);
	}

	/**
	 * 删除部门
	 */
	@SysLog(module = ModuleConstant.MODULE_DEPARTMENT)
	@PostMapping("/delete")
	public Object deleteDepartment(Long departmentId) {
		return departmentService.deleteDepartment(departmentId);
	}

	/**
	 * 部门列表
	 */
	@PostMapping(value = "/list")
	public Object listDepartment(Integer status, String departmentName, Integer pageNum, Integer pageSize) {
		PageInfo<DepartmentListVO> pageInfo = departmentService.listDepartment(status, departmentName, pageNum, pageSize);
		return pageInfo;
	}

	/**
	 * 部门选择列表
	 */
	@PostMapping("/listDepartmentSelect")
	public Object listDepartmentSelect() {
		return departmentService.listDepartmentSelect();
	}


	/**
	 * 启用禁用部门
	 */
	@SysLog(module = ModuleConstant.MODULE_DEPARTMENT)
	@PostMapping(value = "/enableDisableDepartment")
	public Object enableDisableDepartment(Long departmentId,Integer status) {
		return departmentService.enableDisableDepartment(departmentId,status);
	}

	/**
	 * 获取部门树列表
	 */
	@PostMapping(value = "/listDepartmentTree")
	public Object listDepartmentTree() {
		return departmentService.listDepartmentTree();
	}

}
